package com.example.a2306_shop.adapter

import android.graphics.Paint
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2306_fx.R
import com.example.base.entity.Product


class ProductAdapter:BaseQuickAdapter<Product,BaseViewHolder>(R.layout.item_product) {
    override fun convert(holder: BaseViewHolder, item: Product) {
        Glide.with(context).load(item.image).into(holder.getView(R.id.product_iv))
        holder.setText(R.id.product_price,"￥${item.price}")
        holder.setText(R.id.product_name,item.storeName)
        holder.setText(R.id.product_otprice,"￥${item.otPrice}")
        holder.setText(R.id.product_sale,"已售${item.sales+item.ficti}件")//显示的销量为 销量+虚拟销量 //首页商品数据请求时，注意将字段改为Int
        //原价显示被横线划掉效果
        holder.getView<TextView>(R.id.product_otprice).paintFlags = Paint.STRIKE_THRU_TEXT_FLAG
    }
}

class ProductMuAdapter:BaseMultiItemQuickAdapter<Product,BaseViewHolder>(){
    init {
        addItemType(0,R.layout.item_product)
        addItemType(1,R.layout.item_product)
    }
    override fun convert(holder: BaseViewHolder, item: Product) {
        holder.setText(R.id.product_price,"￥${item.price}")
        holder.setText(R.id.product_name,item.storeName)
        if(item.type==0){
            Glide.with(context).load(item.image).circleCrop().into(holder.getView(R.id.product_iv))
        }else{
            Glide.with(context).load(item.image).transform(CenterCrop(),RoundedCorners(20)).into(holder.getView(R.id.product_iv))

        }
    }

}